package Linklist;

import java.util.Scanner;

public class Animal {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt(); // 数据组数

        for (int i = 0; i < T; i++) {
            int n = scanner.nextInt(); // 榜单上的歌的数目
            int[] rankAdjustments = new int[n + 1]; // 用来记录每首歌的调整意见
            boolean isValid = true;

            for (int j = 0; j < n; j++) {
                int songRank = scanner.nextInt();
                int adjustment = scanner.nextInt();

                if (adjustment == 1) { // 排名太低了，应该高一些
                    rankAdjustments[songRank]++;
                } else if (adjustment == -1) { // 排名太高了，应该低一些
                    rankAdjustments[songRank]--;
                } else { // 排名合理
                    // 不需要调整
                }

                // 检查是否有冲突
                if (rankAdjustments[songRank] > 1 || rankAdjustments[songRank] < -1) {
                    isValid = false;
                    break;
                }
            }

            // 输出结果
            System.out.println(isValid ? "YES" : "NO");
        }

        scanner.close();
    }


    public static int countPermutations(char[] input, int start, int end) {
        if (start >= end) {
            return 1;
        }

        int count = 0;
        for (int i = start; i <= end; i++) {
            if (isValid(input, start, i)) {
                // 递归计算左子树和右子树的可能性
                int left = countPermutations(input, start + 1, i);
                int right = countPermutations(input, i + 1, end);
                count += left * right;
            }
        }

        return count;
    }

    public static boolean isValid(char[] input, int start, int end) {
        for (int i = start; i < end; i++) {
            if (input[i] == input[end]) {
                return false;
            }
        }
        return true;
    }
}

 class Dog extends Animal {
    public void makesound(){
        System.out.println("汪汪汪");

}
}

class Cat extends Animal {
    public void makesound(){
        System.out.println("mmm");

    }
}

